<template>
	<el-dialog v-model="visible" title="用户信息" :close-on-click-modal="false">
		<el-form ref="dataFormRef" :model="dataForm" label-width="100px" :disabled="true">
			<el-form-item label="用户头像" prop="headImage">
				<el-avatar shape="square" :size="100" :src="dataForm.headImage"></el-avatar>
			</el-form-item>
			<el-form-item label="用户id" prop="id">
				<el-input v-model="dataForm.id"></el-input>
			</el-form-item>
			<el-form-item label="用户名" prop="userName">
				<el-input v-model="dataForm.userName"></el-input>
			</el-form-item>
			<el-form-item label="用户昵称" prop="nickName">
				<el-input v-model="dataForm.nickName"></el-input>
			</el-form-item>
			<el-form-item label="性别" prop="sex">
				<ma-dict-label dict-type="user_gender" :dict-value="dataForm.sex" />
			</el-form-item>
			<el-form-item label="个性签名" prop="signature">
				<el-input v-model="dataForm.signature"></el-input>
			</el-form-item>
			<el-form-item label="最后登录时间" prop="lastLoginTime">
				<el-input v-model="dataForm.lastLoginTime"></el-input>
			</el-form-item>
			<el-form-item label="注册时间" prop="createdTime">
				<el-input v-model="dataForm.createdTime"></el-input>
			</el-form-item>
			<el-form-item label="是否被封禁" prop="isBanned">
				<ma-dict-label dict-type="boolean_type" :dict-value="dataForm.isBanned ? 1 : 0" />
			</el-form-item>
			<el-form-item v-show="dataForm.isBanned" label="被封禁原因" prop="reason">
				<el-input v-model="dataForm.reason"></el-input>
			</el-form-item>
		</el-form>
		<template #footer>
			<el-button type="primary" @click="visible = false">确定</el-button>
		</template>
	</el-dialog>
</template>

<script setup lang="ts">
import { reactive, ref } from 'vue'
import { useUserApi } from '@/api/im/user'

const emit = defineEmits(['refreshDataList'])

const visible = ref(false)
const dataFormRef = ref()

const dataForm = reactive({
	id: '',
	userName: '',
	nickName: '',
	headImage: '',
	headImageThumb: '',
	sex: '',
	signature: '',
	isBanned: false,
	reason: '',
	lastLoginTime: '',
	createdTime: '',
	type: ''
})

const init = (id: number) => {
	visible.value = true
	getUser(id)

}

const getUser = (id: number) => {
	useUserApi(id).then(res => {
		Object.assign(dataForm, res.data)
	})
}

defineExpose({
	init
})
</script>
